﻿myApp.controller('ContactController', function ($scope, $http) {
    $scope.$emit('newPageLoaded', {
        'title': 'Contact Info | ShiJie Property',
        'description': "Contact Info. Get In Touch With ShiJie Property Today!",
        'keywords': 'contact info, contact shijie property'
    });

  
    $http({
        method: "GET",
        url: "api/Page/GetSetting"
    }).then(function (r) {
        console.log("PASS!");
        $scope.address = r.data.Address;
        $scope.company_contact = "0183987777";
        $scope.mobile_contact = r.data.MobilePhone;
        $scope.email = r.data.Email;
        $scope.latitude = r.data.Latitude;
        $scope.longitude = r.data.Longitude;
    }, function (response) {
        console.log("FAILED!?");
    });

    $scope.googleMapsUrl = "http://maps.google.com/maps/api/js?key=AIzaSyChZZpYsR0zI5fDC-TW8vPFeWw2LYdXZ7g";
    $scope.customIcon = {
        "url": "/images/markers/coral-marker-cozy.png"
    };
    
    $scope.sendMessage = function () {
        $scope.data = {};
        $scope.data.Email = $scope.contact_email;
        $scope.data.Title = $scope.subject;
        $scope.data.Body = $scope.message + "<br/><br/><br/> This message is sent from Shi Jie Property Website Contact Page:<br/>Name: " + $scope.contact_name + "<br/>Email: " + $scope.contact_email;

         console.log(JSON.stringify($scope.data));

        $http.post('/api/User/sendEmail', $scope.data, {
                headers:{ 'Content-Type': 'application/json;charset=UTF-8'}
        }).success(function (response) {
                console.log("SUCCESS!: " +JSON.stringify(response));
                alert("Thanks for submitting, we will contact you soon.");
                $scope.name = "";
                $scope.contact_email = "";
                $scope.subject = "";
                $scope.message = "";
         }).error(function(error) {
                alert("ERROR: " +JSON.stringify(error));
        });

    }
    

    $scope.options = {
        panControlOptions: {
            position: google.maps.ControlPosition.LEFT_TOP
        },
        styles: [{
            featureType: "all",
            elementType: "all",
            stylers: [
                { saturation: -100 }
            ]
        }],
        scrollwheel: false,
        panControl: false,
        mapTypeControl: false,
        zoomControl: true,
    };

});